package com.rd.student.ruanjian.class4.lichunquan.Text03;

import java.util.concurrent.atomic.AtomicInteger;

public class Test04 {
    public static void main(String[] args) {
        //过山洞人员名名单
        String[] name = {"赵一","钱二","孙三","李四","王五","周六","周日"
                ,"星期八","久九","第十"};
        Method method =new Method();
        for (int i = 0; i < name.length; i++) {
            new Thread(method, name[i]).start();
        }
//        创建十个线程同时运行
        new Thread(method,"赵一").start();
        new Thread(method,"钱二").start();
        new Thread(method,"孙三").start();
        new Thread(method,"李四").start();
        new Thread(method,"王五").start();
        new Thread(method,"周六").start();
        new Thread(method,"周日").start();
        new Thread(method,"星期八").start();
        new Thread(method,"久九").start();
        new Thread(method,"第十").start();

    }
}
class Method implements Runnable{
    AtomicInteger a = new AtomicInteger(0);
    @Override
    public void run() {
        synchronized (this) {
            System.out.println(Thread.currentThread().getName() +
                    "正在通过。。。。。。");

            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            a.getAndIncrement();
            System.out.println(Thread.currentThread().getName() +
                    "序号为：" +a);
        }

    }
}
